
*************************************************************************
*																		*
*					Campaign Panel Book Chapter 4 - Charts Individual Votes Parties for all Waves 2009 + 2013				*
*																		*
*************************************************************************	


*Votes
*2009
tab a_wabsrestr_novote1_w2 if a_anzahlwechsel_novote_w2!=.  // Dummygrundlage

fre ?_wabsrestr_novote*


*Share of party vote

tab a_wabsrestr_novote1_w2 if a_anzahlwechsel_novote_w2!=. [aweight=a_weight],matcell(x)
matrix list x
svmat x
list x1 in 1/7
rename x1 a_all1



foreach num of numlist 2/7 {
tab a_wabsrestr_novote`num' if a_anzahlwechsel_novote_w2!=. [aweight=a_weight],matcell(x)
matrix list x
svmat x
list x* in 1/7
rename x1 a_all`num'

}



foreach num of numlist 1/7 {
tab b_wabsrestr_novote`num' if b_anzahlwechsel_novote!=. [aweight=b_weight],matcell(x)
matrix list x
svmat x
list x* in 1/7
rename x1 b_all`num'

}


foreach party in all {
foreach num of numlist 1/7{
replace a_`party'`num' = 0 if a_`party'`num'==.
replace b_`party'`num' = 0 if b_`party'`num'==.
}
}

* Create ID-variable in order to be able to export data
gen id_graph = _n if a_all1!=0

drop if a_all1==0

keep ?_all?  id_graph

sort id_graph

list a_all1

foreach year in a b {
foreach party in all {
foreach num of numlist 1/7 {

egen `year'_`party'total`num' = total(`year'_`party'`num')


}
}
}
*

foreach year in a b {
foreach party in all {
foreach num of numlist 1/7 {

gen `year'_share`party'total`num' = `year'_`party'`num'/`year'_`party'total`num'


}
}
}
*


save "${path}\Reproducible Do-Files\Chapter 4\Figure\Graphik Data.dta", replace

* Chart for party identification without confidence intervals

* Separate charts for 2009 and 2013

cap ssc inst sxpose

keep a_sharealltotal?

xpose, clear varname

rename v1 cdu
rename v2 spd
rename v3 fdp
rename v4 gru
rename v5 lin
rename v6 others
rename v7 undecide

gen welle= _n


graph twoway connected cdu spd fdp gru lin others undecide welle, sort ///
	xlabel(1/7)  scheme(s1mono) ///
	title("", ///
	size(normal) margin(medium)) legend(label(1 CDU/CSU) label(2 SPD) label(3 FDP) label(4 Greens) label(5 Left Party) label(7 Undecided) label(6 Others) ///
	region(lcolor(none)) style(column) position(6) row(3)) xtitle("Wave", margin(medium)) ytitle("Share of votes", margin(vsmall)) ///
	lpattern(dash vshortdash longdash longdash_dot dash_dot dot solid)  msymbol(D S X T + d O) mcolor(gs10 gs8 black gs4 gs12 gs2 gs6) ///
	ylabel(0(0.1)0.4) name(all09_3, replace)	
graph export "${path}\Reproducible Do-Files\Chapter 4\All 2009_onegraph.png", width(2000) ///
	height(1800) replace


save "${path}\Reproducible Do-Files\Chapter 4\Figure\All 2009.dta", replace



use "${path}\Reproducible Do-Files\Chapter 4\Figure\Graphik Data.dta", clear

keep b_sharealltotal?

xpose, clear varname

rename v1 cdu
rename v2 spd
rename v3 fdp
rename v4 gru
rename v5 lin
rename v6 others
rename v7 undecide

gen welle= _n

	
graph twoway connected cdu spd fdp gru lin others undecide welle, sort ///
	xlabel(1/7)  scheme(s1mono) ///
	title("", ///
	size(normal) margin(medium)) legend(label(1 CDU/CSU) label(2 SPD) label(3 FDP) label(4 Greens) label(5 Left Party) label(7 Undecided) label(6 Others) ///
	region(lcolor(none)) style(column) position(6) row(3)) xtitle("Wave", margin(medium)) ytitle("Share of votes", margin(vsmall)) ///
	lpattern(dash vshortdash longdash longdash_dot dash_dot dot solid)  msymbol(D S X T + d O) mcolor(gs10 gs8 black gs4 gs12 gs2 gs6) ///
	ylabel(0(0.1)0.4) name(all13_3, replace)	
graph export "${path}\Reproducible Do-Files\Chapter 4\All 2013_onegraph.png", width(2000) ///
	height(1800) replace


save "${path}\Reproducible Do-Files\Chapter 4\Figure\All 2013.dta", replace


